/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
**/
define("pages/jbxx/jbxx_dynamic", [
        "../../common/componts.js",
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate"
    ],
    function(require) {
        var componts = require("../../common/componts");
        var queryTableId="awdDynamicQueryTableId";
        var selectid;

        var getQueryDataGrid = function(){
            return $("#"+queryTableId);
        };

        var tableInit=function(){
            componts.initTable(queryTableId,{
                url:"/jbxx/list",
                title:'',
                fit:true,
                // firstLoad:true,
                width:'100%',
                columns :  [
                    {field: 'id',title: '',width:30,hidden:true}
                    ,{field:'barjh',title:'办案人警号 多个以逗号或空格分开',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jslyString',title:'拒收理由',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xhayString',title:'细化案由',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jy',title:'就医',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gyjsrqString',title:'关押结束日期',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gyts',title:'羁押天数',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jljdjg',title:'JLJDJG',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ryzwbjString',title:'人员指纹标记',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'cszwyzString',title:'出所指纹验证',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jsbh',title:'监所编号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'snbh',title:'所内编号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jsh',title:'拘室号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'wbrybh',title:'网办人员编号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gcbh',title:'过程编号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xm',title:'姓名',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xmpy',title:'姓名拼音',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xmpyszm',title:'姓名拼音首字母',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'bm',title:'别名',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'bmty',title:'别名同音',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xbString',title:'性别',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'csrqString',title:'出生日期',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjlxString',title:'证件类型',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zjh',title:'证件号',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'hyzkString',title:'婚姻状况',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'mzString',title:'民族',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gjString',title:'国籍',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'hjdString',title:'户籍地',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'hjdxz',title:'户籍地详址',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xzdString',title:'现住地',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'xzdxz',title:'现住地详址',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'whcdString',title:'文化程度',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zyString',title:'职业',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gzdw',title:'工作单位',width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                ] ,
                //基本信息双击事件
                onDblClickRow:function(rowIndex, rowData){
                    $("input[name='ryRadio']")[rowIndex].checked = true;
                    getQueryDataGrid().datagrid("selectRow", rowIndex);
                    selectid=rowData.id;
                },
                onLoadSuccess:function(data){
                    if(data.total>0){
                        getQueryDataGrid().datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }
                },
                //单击行选中取消事件
                onClickRow:function(rowIndex, rowData){
                    if(selectid!=rowData.id){
                        $("input[name='ryRadio']")[rowIndex].checked = true;
                        selectid=rowData.id;
                    }else{
                        getQueryDataGrid().datagrid("unselectRow",rowIndex);
                        $("input[name='ryRadio']")[rowIndex].checked = false;
                        getQueryDataGrid().datagrid('clearSelections');
                        selectid="";
                    }
                }
                });
                //页面高度自适应
                getQueryDataGrid().datagrid('resize',{
                    height:($(window).height()-150)
                });
            };

        /**
         * 数据列表刷新加载
         */
        var loadDataGrid = function(){
            var formData = $(".awd-dynamic-query-form").serializeObject();
            var queryParams = $.extend({},formData,{"state":"R2"});
            $.ajax({
                type : "POST",
                url : '/xxxx/dynamic',
                data : queryParams,
                success : function(result) {
                    console.log(result);
                    if (result.success) {
                        $.messager.alert("确定","数据加载成功","info");
                    }else{
                        $.messager.alert("确定","数据加载失败","warn");
                    }
                },
                complete:function(){
                }
            });
        };

        var bindAction=function(){
            //查询
            $(".awd-dynamic-query-btn").on("click",function(){
                loadDataGrid();
            });

            /**
             * 绑定回车事件
             */
            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    loadDataGrid();
                }
            });

        };

        //初始化
        (function(){
            componts.initSelectPage(undefined);
            componts.initSelect(undefined,undefined,undefined);
            // tableInit();
            bindAction();
        })()
    });
